package com.itya.weatherback.utils;


import java.util.HashMap;
import java.util.Map;

public class WindDirectionUtils {
    private static final Map<String, String> DIRECTION_MAP = new HashMap<>();

    static {
        DIRECTION_MAP.put("N", "北风");
        DIRECTION_MAP.put("S", "南风");
        DIRECTION_MAP.put("E", "东风");
        DIRECTION_MAP.put("W", "西风");
        DIRECTION_MAP.put("NE", "东北风");
        DIRECTION_MAP.put("NW", "西北风");
        DIRECTION_MAP.put("SE", "东南风");
        DIRECTION_MAP.put("SW", "西南风");
    }

    public static String getChineseDirection(String code) {
        return DIRECTION_MAP.getOrDefault(code, "未知风向");
    }

    // 文件路径: C:\Users\29285\Desktop\weatherBack\src\main\java\com\itya\weatherback\controller\weatherController.java
    public static int extractWindLevel(String ws) {
        try {
            // 提取数字部分（支持"2级"、"3-4级"等格式）
            if (ws != null && ws.matches(".*\\d+.*")) {
                return Integer.parseInt(ws.replaceAll("[^0-9]", ""));
            }
            return 0;
        } catch (NumberFormatException e) {
            System.out.println("风速等级解析失败: " + ws);
            return 0;
        }
    }

}

